import { defineStore } from 'pinia';
import api from '@/api';
import { ElMessage } from 'element-plus';

export const useAiChatStore = defineStore('role', {
  state: () => {
    return {
      content: {
        text: '',
      }
    }
  },

  actions: {
    //与ai进行交流
    async fetchAiChat(modelName:string,message: string) {
      const res = await api.aiChats.aichat({modelName,message}) ;
      if (res.code === 200) {

        this.content.text = res.data
        console.log("后端返回的数据-----》");
        console.log(this.content.text);
        return this.content.text; // 返回数据以便在组件中直接使用
      } else {
        // 处理非200状态码
        console.error("API错误:", res);
        ElMessage.error(`AI请求失败: ${res.msg || '未知错误'}`);
        return null;
      }
    },
  }





})
